package com.demo.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/resp")
public class RespController {

    /**
     * 使用SpringMVC默认的响应方式
     */
    @RequestMapping("/mv")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("name","张三");
        mv.addObject("age",18);
        // 这里设置的名称，就是将来需要给客户端展示的html、jsp、excel等资源的名称
        // 例如：index.jsp   index.html
        mv.setViewName("index");
        return mv;
    }

    @RequestMapping("/base")
    @ResponseBody
    public Integer base(){
        System.out.println("base");
        return 1;
    }
    @RequestMapping("/str")
    @ResponseBody
    public String str(){
        System.out.println("str");
        return "hello springmvc";
    }

}
